$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'deviceinformation/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '设备品牌', name: 'deviecBrand', index: 'deviec_brand', width: 80 }, 			
			{ label: '机械类型（0-12对应挖掘机、装载机、矿用自卸车、推土机、压路机、平地机、混凝土机械、桩工机械、凿岩机械、摊铺机、俩头忙、旋挖钻、叉车）', name: 'machineryType', index: 'machinery_type', width: 80 }, 			
			{ label: '出厂日期', name: 'dateOfProduction', index: 'date_of_production', width: 80 }, 			
			{ label: '设备型号', name: 'plateSubject', index: 'plate_subject', width: 80 }, 			
			{ label: '发动机型号', name: 'engineSubject', index: 'engine_subject', width: 80 }, 			
			{ label: '功率', name: 'power', index: 'power', width: 80 }, 			
			{ label: '购买日期', name: 'resBuyDate', index: 'res_buy_date', width: 80 }, 			
			{ label: '发动机编号', name: 'enginePlateNum', index: 'engine_plate_num', width: 80 }, 			
			{ label: '设备是（0国产，1合资，2进口）', name: 'productionType', index: 'production_type', width: 80 }, 			
			{ label: '设备产地', name: 'productionAddress', index: 'production_address', width: 80 }, 			
			{ label: '行走方式(0轮式，1履带)', name: 'maneuver', index: 'maneuver', width: 80 }, 			
			{ label: '工作时长', name: 'workTime', index: 'work_time', width: 80 }, 			
			{ label: '燃料类型（0柴油，1汽油，2天然气）', name: 'fuel', index: 'fuel', width: 80 }, 			
			{ label: '尾气排放值(0未检测 1已检测)', name: 'outputVolume', index: 'output_volume', width: 80 }, 			
			{ label: '出厂编号', name: 'factoryNum', index: 'factory_num', width: 80 }, 			
			{ label: '车牌号', name: 'plateNum', index: 'plate_num', width: 80 }, 			
			{ label: '归属人身份证号', name: 'identification', index: 'identification', width: 80 }, 			
			{ label: '设备所有人姓名(个人或企业名称)', name: 'registerName', index: 'register_name', width: 80 }, 			
			{ label: '创建时间', name: 'createDate', index: 'create_date', width: 80 }, 			
			{ label: '抵押状态1、已抵押 ,0、未抵押', name: 'mortgage', index: 'mortgage', width: 80 }, 			
			{ label: '读取状态1、已读 ,0、未读', name: 'state', index: 'state', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		deviceInformation: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.deviceInformation = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.deviceInformation.id == null ? "deviceinformation/save" : "deviceinformation/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.deviceInformation),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "deviceinformation/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "deviceinformation/info/"+id, function(r){
                vm.deviceInformation = r.deviceInformation;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});